package com.business.sys.controller;


import com.business.common.dto.R;
import com.business.redis.constant.RedisKeyConstant;
import com.business.redis.utils.RedisUtil;
import com.business.sys.entity.IndustryCategory;
import com.business.sys.service.IndustryCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 行业分类表: 后端controller类
 *
 * @author chenjiehong
 * @date 2019-11-29 14:20:12
 * @since 1.0
 */
@RestController
@RequestMapping(value = "/industryCategory")
public class IndustryCategoryController {


    @Autowired
    private IndustryCategoryService industryCategoryServiceImpl;


    /**
     * 查询行业分类
     *
     * @param industryCategory
     * @date 2019-04-28 15:03:17
     */
    @GetMapping("/query")
    @ResponseBody
    public R query(@RequestParam IndustryCategory industryCategory) {
        String key = String.format(RedisKeyConstant.INDUSTRY_CATEGORY_QUERY, industryCategory);
        if (!RedisUtil.hasKey(key)) {
            List<IndustryCategory> r = industryCategoryServiceImpl.query(industryCategory);
            RedisUtil.setValue(key, r);
            return R.success(r);
        } else {
            return R.success(RedisUtil.getArray(key, IndustryCategory.class));
        }
    }


    /**
     * 查询行业分类
     *
     * @date 2019-04-28 15:03:17
     */
    @GetMapping("/queryAll")
    @ResponseBody
    public R queryAll() {
        String key = RedisKeyConstant.INDUSTRY_CATEGORY_QUERY_ALL;
        if (!RedisUtil.hasKey(key)) {
            List<Map<String, Object>> r = industryCategoryServiceImpl.queryAll();
            RedisUtil.setValue(key, r);
            return R.success(r);
        } else {
            return R.success(RedisUtil.getArray(key, IndustryCategory.class));
        }
    }


}